<!-- Ant build file for Swift Mailer (Standard Edition) -->
<project name="Swift Mailer SE" default="bundle">

  <!-- Config settings -->
  <property name="path" value="." />
  <property name="builddir" value="${path}/build" />
  <property name="src.versionfile" value="${path}/VERSION" />
  <!-- Generate version info from VERSION file -->
  <loadfile property="bundle.name" srcFile="${src.versionfile}">
    <filterchain>
      <striplinebreaks />
    </filterchain>
  </loadfile>
  <!-- Generate version number -->
  <loadfile property="bundle.version" srcFile="${src.versionfile}">
    <filterchain>
      <striplinebreaks />
      <tokenfilter>
        <replacestring from="Swift-" to=""/>
      </tokenfilter>
    </filterchain>
  </loadfile>
  <property name="src.readmefile" value="${path}/README" />
  <property name="src.changesfile" value="${path}/CHANGES" />
  <property name="src.libdir" value="${path}/lib" />
  <property name="src.tests" value="${path}/tests" />
  <property name="builddir.package" value="${builddir}/${bundle.name}" />
  <property name="runtests" value="" />
  <filelist id="src.licenses" dir="${path}">
    <file name="LICENSE" />
  </filelist>


  <!-- Bundle all files into a central location -->
  <target name="bundle" depends="prepare, clean, copy-classes">
    <copy file="${src.versionfile}" todir="${builddir.package}" />
    <copy file="${src.changesfile}" todir="${builddir.package}" />
    <copy todir="${builddir.package}">
      <filelist refid="src.licenses" />
    </copy>
    <copy file="${src.readmefile}" todir="${builddir.package}" />
    <move file="${builddir.package}/tests/acceptance.conf.php.default"
      tofile="${builddir.package}/tests/acceptance.conf.php" />
    <move file="${builddir.package}/tests/smoke.conf.php.default"
      tofile="${builddir.package}/tests/smoke.conf.php" />
  </target>

  <!-- Copy some *.default files to their required files if needed -->
  <target name="prepare">
    <copy file="${src.tests}/acceptance.conf.php.default"
      tofile="${src.tests}/acceptance.conf.php" />
      <copy file="${src.tests}/smoke.conf.php.default"
        tofile="${src.tests}/smoke.conf.php" />
  </target>

  <!-- Clean out the build directory -->
  <target name="clean">
    <delete includeemptydirs="true">
      <fileset dir="${builddir}" includes="**/*" />
    </delete>
  </target>

  <!-- Copy all classes from the class path to the bundle -->
  <target name="copy-classes">
    <copy todir="${builddir.package}/lib">
      <fileset dir="${src.libdir}" />
      <filterchain>
        <replacetokens>
          <token key="SWIFT_VERSION_NUMBER" value="${bundle.version}"/>
        </replacetokens>
      </filterchain>
    </copy>
    <copy todir="${builddir.package}/tests">
      <fileset dir="${src.tests}" />
    </copy>
  </target>

  <!-- Package up the project as a gzip file -->
  <target name="package" depends="bundle">
    <tar destfile="${builddir.package}.tar.gz" compression="gzip" longfile="gnu">
      <fileset dir="${builddir}" />
    </tar>
    <delete includeemptydirs="true">
      <fileset dir="${builddir.package}" includes="**" />
    </delete>
  </target>

  <!-- Run the included unit tests -->
  <target name="test" depends="prepare, clean, copy-classes">
    <exec executable="phpunit" failonerror="true" />
  </target>

</project>
